package com.joplus.housekeeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.bean.PassengerListBean;
import com.joplus.housekeeper.utils.StringUtils;

import java.util.List;

/**
 * author： ccm
 * time： 2017/6/13.
 * description：
 */

public class ContactAdapter extends BaseAdapter {
    Context mContext;
    List<PassengerListBean.DataBean.PassengersBean> passengers;
    private LayoutInflater layout;

    public ContactAdapter(Context context, List<PassengerListBean.DataBean.PassengersBean> passengers) {
        mContext = context;
        this.passengers = passengers;
        layout = LayoutInflater.from(context);
    }



    @Override
    public int getCount() {
        return passengers.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = layout.inflate(R.layout.item_contacts, null);
        ImageView iv = (ImageView) view.findViewById(R.id.iv);
        TextView tv_name = (TextView) view.findViewById(R.id.tv_name);
        TextView tv_phone = (TextView) view.findViewById(R.id.tv_phone);
        ImageView iv_del = (ImageView) view.findViewById(R.id.iv_del);
        if ("1".equals(passengers.get(position).getGender())) {
            iv.setImageResource(R.drawable.check_man_c);
        } else {
            iv.setImageResource(R.drawable.check_woman_c);
        }
        StringUtils.setText(tv_name, passengers.get(position).getName());
        if ("1".equals(passengers.get(position).getCardType())) {
            StringUtils.setText(tv_phone, passengers.get(position).getIdcard());
        } else {
            StringUtils.setText(tv_phone, passengers.get(position).getPassportNumber());
        }
        iv_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                passengers.remove(position);
                notifyDataSetChanged();
            }
        });

        return view;
    }
}
